package dao.impl;

import dao.MonthCallTimeDao;
import domain.MonthCallTime;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import util.JDBCUtils;

import java.util.List;

public class MonthCallTimeDaoImpl implements MonthCallTimeDao {
    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());

    @Override
    public List<MonthCallTime> SelectMonthCallTimeByTelephone(String telephone, int year) {
        String sql = "SELECT month,SUM(call_duration_sum) AS sum FROM( SELECT call_duration_sum,telephone,name,year,month,day FROM tb_call A LEFT JOIN tb_contacts B ON A.id_contact = B.id LEFT JOIN tb_dimension_date C ON A.id_date_dimension = C.id WHERE telephone = "+telephone+" AND year = "+year+" AND month != -1 AND day != -1 ) AS k GROUP BY month";
        List<MonthCallTime> MonthCallTime = template.query(sql, new BeanPropertyRowMapper<MonthCallTime>(MonthCallTime.class));
        return MonthCallTime;
    }
}
